package main

import "github.com/gin-gonic/gin"

type Person struct {
	ID   int    `uri:"id"`
	Name string `uri:"name"`
}

// 参数作为url
func main() {
	r := gin.Default()

	//基本用法
	/*
		 r.GET("/:id/:name", func(c *gin.Context) {
			id := c.Param("id")
			action := c.Param("action")
			c.JSON(200, gin.H{
				"id":     id,
				"action": action,
			})
		})
	*/

	//测试： http://localhost:8080/1/action
	r.GET("/:id/:name", func(c *gin.Context) {
		var p Person
		if err := c.ShouldBindUri(&p); err != nil {
			c.Status(404)
			return
		}
		c.JSON(200, gin.H{
			"id":     p.ID,
			"action": p.Name,
		})
	})
	r.Run()
}
